#ifndef __VIEW_REGION_H
#define __VIEW_REGION_H

#include <lib/type.h>

#define VIEW_DRAG_REGION_NUM 4

typedef struct
{
    int x;
    int y;
} view_point_t;

typedef struct
{
    int x;
    int y;
    union
    {
        uint32_t uw;
        int sw;
    } w;
    union
    {
        uint32_t uh;
        int sh;
    } h;
} view_rect_t;

typedef struct
{
    uint64_t timer_id;
    uint64_t interval;
} viewio_timer_t;

typedef struct
{
    int left;
    int top;
    int right;
    int bottom;
} view_region_t;

#define ViewRegionInRange(region,x,y) ((x)>=(region)->left&&(x)<=(region)->right&&(y)>=(region)->top&&(y)<=(region)->bottom)

static inline void ViewRegionReset(view_region_t *region)
{
    region->left = -1;
    region->top = -1;
    region->right = -1;
    region->bottom = -1;
}

static inline void ViewRegionInit(view_region_t *region, int left, int top, int right, int bottom)
{
    region->left = left;
    region->top = top;
    region->right = right;
    region->bottom = bottom;
}

static inline int ViewRegionValid(view_region_t *region)
{
    if (region->left >= 0 && region->top >= 0 && region->bottom >= 0 && region->right >= 0)
        return 1;
    return 0;
}

static inline void ViewRegionCopy(view_region_t *dst, view_region_t *src)
{
    *dst = *src;
}

static inline void ViewRectInit(view_rect_t *rect, int x, int y, int width, int height)
{
    rect->x = x;
    rect->y = y;
    rect->h.uh = height;
    rect->w.uw = width;
}

static inline void ViewRectReset(view_rect_t *rect)
{
    rect->x = 0;
    rect->y = 0;
    rect->w.uw = 0;
    rect->h.uh = 0;
}

static inline int ViewRectValid(view_rect_t *rect)
{
    return (rect->w.uw > 0 && rect->h.uh > 0);
}

static inline void ViewRectCopy(view_rect_t *dst, view_rect_t *src)
{
    *dst = *src;
}

#endif